package com.zls.service.impl;

import com.zls.mapper.StageMapper;
import com.zls.mapper.SubitemMapper;
import com.zls.page.PageResult;
import com.zls.page.QueryPageBean;
import com.zls.pojo.Stage;
import com.zls.pojo.Subitem;
import com.zls.service.StageService;
import com.zls.service.SubitemService;
import com.zls.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class SubitemServiceImpl implements SubitemService {
    @Autowired
    private SubitemMapper subitemMapper;
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageResult pageResult = new PageResult();
        Integer currentPage = queryPageBean.getCurrentPage();//当前页
        Integer pageSize = queryPageBean.getPageSize();//每页大小
        String queryString = queryPageBean.getQueryString();//查询条件
        //total总记录数
        List<Subitem> page = subitemMapper.findSub((currentPage - 1) * pageSize, pageSize,queryString);
        //rows  当前页的数据
        Long count = subitemMapper.count(queryString);
        pageResult.setRows(page);
        pageResult.setTotal(count);
        return pageResult;
    }

    @Override
    public List<Subitem> findAll() {
        return subitemMapper.findAll();
    }

    @Override
    @Transactional
    public int addSubitem(Subitem subitem) {
        subitem.setUpdatetime(new Date());
        subitem.setSuid(UUIDUtils.uuid());
        int i = subitemMapper.addSubitem(subitem);
        return i;
    }

    @Override
    @Transactional
    public Subitem findBySuid(String suid) {
        return subitemMapper.findBySuid(suid);
    }

    @Override
    @Transactional
    public int editSubitem(Subitem subitem) {
        subitem.setUpdatetime(new Date());
        int i = subitemMapper.updateSubitem(subitem);
        return i;
    }

    @Override
    @Transactional
    public int deleteSubitem(String suid) {
        int i = subitemMapper.deleteSubitem(suid);
        return i;
    }

    @Override
    public List<Subitem> findByPid(int pid) {
        return subitemMapper.findByPid(pid);
    }
}
